import { defineStore } from "pinia";
import piniaPersistConfig from "@/stores/helper/persist";

// export const useInfoStore = defineStore({
//   // id: "geeker-user",
//   id: "tzh",
//   state: () => ({
//     avatar: "",
//     email: "",
//     address: "",
//     sex: "",
//     age: 0,
//     nickName: "",
//     username: ""
//   }),
//   getters: {},
//   actions: {
//     setInfo(userInfo: {
//       avatar: string;
//       email: string;
//       address: string;
//       sex: string;
//       age: number;
//       nickName: string;
//       username: string;
//     }) {
//       this.avatar = userInfo.avatar;
//       this.email = userInfo.email;
//       this.address = userInfo.address;
//       this.sex = userInfo.sex;
//       this.age = userInfo.age;
//       this.nickName = userInfo.nickName;
//       this.username = userInfo.username;
//     },

//     clearInfo() {
//       this.avatar = "";
//       this.email = "";
//       this.address = "";
//       this.sex = "";
//       this.age = 0;
//       this.nickName = "";
//       this.username = "";
//     }
//   },
//   persist: piniaPersistConfig("tzh")
// });
interface UserInfo {
  avatar: string;
  email: string;
  address: string;
  sex: string;
  age: number;
  nickName: string;
  username: string;
}

export const useInfoStore = defineStore({
  id: "tzh",
  state: (): { userInfo: UserInfo } => ({
    userInfo: {
      avatar: "",
      email: "",
      address: "",
      sex: "",
      age: 0,
      nickName: "",
      username: ""
    }
  }),
  actions: {
    setInfo(userInfo: UserInfo) {
      this.userInfo = userInfo;
    },
    clearInfo() {
      this.userInfo = {
        avatar: "",
        email: "",
        address: "",
        sex: "",
        age: 0,
        nickName: "",
        username: ""
      };
    }
  },
  persist: piniaPersistConfig("tzh")
});
